package io.github.hadyang.leetcode.offer;

import io.github.hadyang.leetcode.TreeNode;

/** @author haoyang.shi */
public class TreeDepth {

  public int TreeDepth(TreeNode root) {
    int[] max = {0};
    depth(root, max, 1);
    return max[0];
  }

  private void depth(TreeNode root, int[] max, int curDepth) {
    if (root == null) return;

    if (curDepth > max[0]) max[0] = curDepth;

    depth(root.left, max, curDepth + 1);
    depth(root.right, max, curDepth + 1);
  }
}
